<template>
  <div class="wa-keep-alive-content wa-posr">
    <div :class="['wa-keep-item','wa-posr',item.active?'wa-active':'']"
         @click="clickHandler(item)"
         v-for="(item,index) in frameTabStore.tabs" v-bind:key="index">
      {{ item.name }}
      <a class="wa-posa wa-close-btn" v-show="item.active"
         @click.stop="true"
         @click="closeTab(item)"
         v-if="index> 0"
      >
        <el-icon>
          <Close/>
        </el-icon>
      </a>
    </div>
    <el-dropdown trigger="click" class="wa-posa wa-tab-menu">
        <span class="el-dropdown-link">
          <el-icon size="16px" class="el-icon--right"><arrow-down/></el-icon>
        </span>
      <template #dropdown>
        <el-dropdown-menu>
          <el-dropdown-item :icon="Refresh">刷新</el-dropdown-item>
          <el-dropdown-item :icon="Close" divided>关闭当前标签</el-dropdown-item>
          <el-dropdown-item :icon="Minus">关闭所有标签</el-dropdown-item>
          <el-dropdown-item :icon="ArrowLeft">关闭左侧标签</el-dropdown-item>
          <el-dropdown-item :icon="ArrowRight">关闭右侧标签</el-dropdown-item>
        </el-dropdown-menu>
      </template>
    </el-dropdown>
  </div>
</template>

<script setup>

import {ArrowDown, ArrowLeft, ArrowRight, Close, Minus, Refresh} from "@element-plus/icons-vue";
import {useFrameTabStore} from "@/store/frame-tab";

const frameTabStore = useFrameTabStore()

const clickHandler = (k) => {
  frameTabStore.active(k.key)
}

const closeTab = (k) => {
  frameTabStore.remove(k.key)
}
</script>

<style lang="less" scoped>
.wa-keep-alive-content {
  border-top: 1px solid #eaeaea;
  border-bottom: 1px solid #eaeaea;
  min-height: 40px;
  line-height: 40px;
  background-color: #fff;
  padding-right: 30px;

  .wa-tab-menu {
    height: 40px;
    line-height: 50px;
    right: 0;
    width: 30px;
    text-align: center;
    cursor: pointer;
  }

  .wa-keep-item.wa-active {
    color: #4195fb;
    border-bottom: 2px solid #4195fb;
    box-sizing: border-box;
  }

  .wa-keep-item:hover {
    color: #4195fb;
    border-bottom: 2px solid #4195fb;

    .wa-close-btn {
      display: block !important;
    }
  }

  .wa-keep-item {
    display: inline-block;
    padding: 0 20px;
    cursor: pointer;
    font-size: 14px;
    box-sizing: border-box;

    .wa-close-btn {
      font-size: 12px;
      border-radius: 2px;
      right: 0;
      top: 12px;
      display: block;
      height: 15px;
      line-height: 17px;
      padding: 0 2px;
      text-align: center;
    }

    .wa-close-btn:hover {
      color: #1d1d1d;
      background-color: #f0f0f0;
    }
  }
}
</style>